<?php

if( !function_exists("ibapithemeset_utf_substr")){  //内容字数截断函数
	function ibapithemeset_utf_substr($str,$len)	{
		if( strlen( $str ) <= $len )
			return $str;
		for($i=0;$i<$len;$i++)
		{
			$temp_str=substr($str,0,1);
			if(ord($temp_str) > 127){
				$i++;
			if($i<$len)    {
				$new_str[]=substr($str,0,3);
				$str=substr($str,3);
				}
			}
		else {
			$new_str[]=substr($str,0,1);
			$str=substr($str,1);
			}
		}
		
		$new_str = join($new_str);
		$new_str = $new_str."...";
		return strip_tags($new_str) ;
	}
}



function ibapithemeset_insert_seo_setting() { //自定义META输出
$options = ibapithemeset_get_options();
$ibapithemeset_active_plugin = $options['active_plugin'];
if ($ibapithemeset_active_plugin === 'true') {
$options = ibapithemeset_get_options(); 
$ibapithemeset_theme_keywords = $options['theme_keywords']; 
$ibapithemeset_theme_descriptions = $options['theme_descriptions'];
$ibapithemeset_theme_contentlimit = $options['theme_contentlimit'];
echo '<!--Custom SEO Setting START echo by Ibapi ThemeSET-->'."\n";

if( !(is_home()) and !(is_single())) {
echo '<meta name="Googlebot" content="noindex,follow" />'."\n";
}
if ( (is_home()) ) {
echo '<meta name="keywords" content="'.$ibapithemeset_theme_keywords.'" />'."\n";
echo '<meta name="description" content="'.$ibapithemeset_theme_descriptions.'" />'."\n";
}elseif (is_single()){
	  global $post, $tags;
    if ($post->post_excerpt) {
        $custom_des = $post->post_excerpt;
    } else {
        $custom_des = ibapithemeset_utf_substr(strip_tags($post->post_content),$ibapithemeset_theme_contentlimit);
    }
 
    $custom_key = "";       
    $custom_tags = wp_get_post_tags($post->ID);
    foreach ($custom_tags as $custom_tag ) {
        $custom_key = $custom_key . $custom_tag->name . ", ";
    }
echo '<meta name="keywords" content="'.$custom_key.'" />'."\n";
echo '<meta name="description" content="'.$custom_des.'" />'."\n";
}
echo '<!--Custom SEO Setting END echo by Ibapi ThemeSET-->'."\n";
}
}
?>